using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using BringelandoEm3D.Core;
using BringelandoEm3D.Objects;

namespace Exercicio8
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        Camera camera;
        Object3D objeto, objeto2, plano;
        KeyboardState teclado;

        public static Game1 instance;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            instance = this;
        }

        protected override void Initialize()
        {
            base.Initialize();            
            
            camera = new Camera
            (
                new Vector3(30, 60, 0),
                new Vector3(0, 0, 0),
                GraphicsDevice.Viewport.AspectRatio
            );

            
        }

        protected override void LoadContent()
        {
            objeto = new Object3D(Content.Load<Model>("Alien Probe/FBX/probe"), GraphicsDevice);
            objeto2 = new Object3D(Content.Load<Model>("Alien Probe/FBX/probe"), GraphicsDevice);
            plano = new Object3D(Content.Load<Model>("chao/plano"), GraphicsDevice);
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            teclado = Keyboard.GetState();
            
            

            camera.chaseObject(objeto2, new Vector3(30, 30, 0));

            if (teclado.IsKeyDown(Keys.Down))
            {
                objeto2.position.Y += 0.5f;
            }
            else if (teclado.IsKeyDown(Keys.Up))
            {

                objeto2.position.Y -= 0.5f;
            }

            if (teclado.IsKeyDown(Keys.Left))
            {
                objeto2.position.Z += 0.5f;
            }
            else if (teclado.IsKeyDown(Keys.Right))
            {
                objeto2.position.Z -= 0.5f;
            }


            //camera.rotationY = 0;

            camera.rotationY += 1f;
            //camera.rotationZ = 1;


            //Console.WriteLine(camera.LookAt.ToString() + " //// " + camera.position + " //// " + objeto2.position); 

            //camera.rotationY += 1;

            objeto.Update();
            objeto2.Update();
            camera.Update();
            
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            eixo.Draw(camera);
            objeto.Draw(camera);
            objeto2.Draw(camera);


            plano.Draw(camera);
            
            base.Draw(gameTime);
        }
    }
}
